package com.newear.happyDialog;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.newear.R;
import com.newear.bean.ReportInfo;
import com.newear.util.MyLogger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by happy on 2018/6/1.
 */

public class HealthStateDialog extends AlertDialog {
    private Context mContext;
    private ImageView closeImageView;
    private String mBtnTopTitle;
    private String mBtnBottomTitle;
    private Button btn_state_define;
    private Button btn_state_reason;
    private TextView tv_define_des;
    private TextView tv_reason_des;
    private ReportInfo.SymptomDefinition mDefinitionItem;

    public HealthStateDialog(Context context, int themeResId, ReportInfo.SymptomDefinition definitionItem) {
        super(context, themeResId);
        mContext = context;
        mDefinitionItem = definitionItem;
        mBtnTopTitle = mDefinitionItem.name + "定义";
        mBtnBottomTitle = mDefinitionItem.name + "病因";
        //点击外面不允许消失
        setCanceledOnTouchOutside(false);
        getWindow().getAttributes().gravity = Gravity.CENTER;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.health_state_layout);
        init();
        findViews();
        setListeners();
        resolveDataInfo();
    }

    private void init(){

    }

    private void findViews(){
        closeImageView = (ImageView) findViewById(R.id.img_state_close);

        btn_state_define = (Button) findViewById(R.id.btn_state_define);
        btn_state_reason = (Button) findViewById(R.id.btn_state_reason);

        tv_define_des = (TextView) findViewById(R.id.tv_define_des);
        tv_reason_des = (TextView) findViewById(R.id.tv_reason_des);
    }

    private void setListeners(){
        closeImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void resolveDataInfo(){
        btn_state_define.setText(mBtnTopTitle);
        btn_state_reason.setText(mBtnBottomTitle);
        tv_define_des.setText(mDefinitionItem.define);
        List<String> defineList = mDefinitionItem.symptoms;
        String reason = "";
        if (defineList != null && defineList.size() > 0){
            for (int i = 0; i < defineList.size(); i++){
                reason =  reason + defineList.get(i) + "\n";
            }
        }
        tv_reason_des.setText(reason);
    }



}
